﻿/**
 * ...
 * @author waneck
 */

package asc;

extern class LoadVars implements Dynamic<String>
{
	
	static inline function __init__():Void
	{
		untyped __js__("asc.LoadVars = LoadVars");
	}
	
	/**
	 * The MIME type sent to the server when you call the LoadVars.send() 
	 * or LoadVars.sendAndLoad() method. The default is application/x-www-urlform-encoded. 
	 */
	var contentType:String;
	
	/**
	 * A boolean value that indicates whether a LoadVars.load()  or LoadVars.sendAndLoad() operation 
	 * has completed (true) or not (false).
	 */
	var loaded:Bool;

	public function new():Void;
	
	/**
	 * Adds or changes HTTP request headers (such as Content-Type or SOAPAction) sent with POST actions.
	 * There are two possible use cases for this method: you can pass two strings, header and headerValue,
	 * or you can pass an array of strings, alternating header names and header values.
	 * 
	 * If multiple calls are made to set the same header name, each successive value replaces the value set
	 * in the previous call.
	 * 
	 * The following standard HTTP headers cannot be added or changed with this method: Accept-Ranges, Age,
	 * Allow, Allowed, Connection, Content-Length, Content-Location, Content-Range, ETag, Host, Last-Modified,
	 * Locations, Max-Forwards, Proxy-Authenticate, Proxy-Authorization, Public, Range, Retry-After, Server,
	 * TE, Trailer, Transfer-Encoding, Upgrade, URI, Vary, Via, Warning, and WWW-Authenticate.
	 * @param	header			A string or an array of strings that represents an HTTP request header name.
	 * @param	headerValue		A string that represents the value associated with header.
	 */
	function addRequestHeader(header:Dynamic, ?headerValue:String):Void;
	
	/**
	 * Converts the query string to properties of the specified LoadVars object. This method is used internally
	 * by the LoadVars.onData()  event handler. Most users do not need to call this method directly. If you override
	 * the LoadVars.onData() event handler, you can explicitly call LoadVars.decode() to parse a string of variables.
	 * @param	queryString		A URL-encoded query string containing name-value pairs.
	 * @return		An object with decoded variables
	 */
	function decode(queryString:String):Dynamic;
	
	/**
	 * Returns the number of bytes loaded from the last or current LoadVars.load() or LoadVars.sendAndLoad()  method call.
	 * The value of the contentType property does not affect the value of getBytesLoaded().
	 * @return	A number.
	 */
	function getBytesLoaded():Int;
	
	/**
	 * Returns the total number of bytes loaded into an object during allLoadVars.load() or LoadVars.sendAndLoad()
	 * LoadVars.load() or LoadVars.sendAndLoad()method calls. Each time a call to load() or sendAndLoad() is issued,
	 * the getBytesLoaded() method is reset, but the getBytesTotal() method continues to grow.
	 * 
	 * @return	A number; Returns undefined if no load operation is in progress or if a load operation has not been 
	 * 		initiated. Returns undefined if the number of total bytes can’t be determined—for example, if the download 
	 * 		was initiated but the server did not transmit an HTTP content length.
	 */
	function getBytesTotal():Null<Int>;
	
	/**
	 * Downloads variables from the specified URL, parses the variable data, and places the resulting variables into the 
	 * LoadVars object that calls the method. You can load variables from a remote URL or from a URL in the local file system; 
	 * the same encoding standards apply to both. 
	 * 
	 * @param	url	A string indicating the URL from which to download variables.
	 * @return	A boolean value indicating success (true) or failure (false).
	 */
	function load(url:String):Bool;
	
	/**
	 * Sends the variables in the myLoadVars object to the specified URL. All enumerable variables in the myLoadVars
	 * object are concatenated into a string that is posted to the URL by using the HTTP POST method. 
	 * 
	 * @param	url		A string; the URL to which to upload variables. 
	 * @param	?target	A File object. If you use this optional parameter, any returned data is output to the specified 
	 * 					File object. If this parameter is omitted, the response is discarded.
	 * @param	?method	A string indicating the GET or POST method of the HTTP protocol. 
	 * 					The default value is POST. This parameter is optional.
	 * @return	A boolean value indicating success (true) or failure (false).
	 */
	function send(url:String, ?target:asc.io.File, ?method:String):Bool;
	
	/**
	 * Posts the variables in the myLoadVars object to the specified URL. The server response is downloaded and parsed 
	 * as variable data, and the resulting variables are placed in the target object. Variables are posted in the same way 
	 * as LoadVars.send(). Variables are downloaded into target in the same way as LoadVars.load().
	 * 
	 * @param	url		A string; the URL to which to upload variables.
	 * @param	target	The LoadVars object that receives the downloaded variables.
	 * @param	?method	A string; the GET or POST  method of the HTTP protocol. The default value is POST.
	 * 				This parameter is optional.
	 * @return
	 */
	function sendAndLoad(url:String, target:LoadVars, ?method:String):Bool;
	
	/**
	 * Returns a string containing all enumerable variables in myLoadVars, in the MIME content encoding
	 * application/x-www-form-urlencoded.
	 * @return
	 */
	function toString():String;
	
	/**
	 * Invoked when data has completely downloaded from the server or when an error occurs while data is downloading from a server. 
	 * 
	 * This handler is invoked before the data is parsed and can be used to call a custom parsing routine instead of the one built in 
	 * to Flash Player. The value of the src parameter that is passed to the function assigned to LoadVars.onData()  can be either 
	 * undefined or a string that contains the URL-encoded name-value pairs downloaded from the server. If the src parameter is
	 * undefined, an error occurred while downloading the data from the server.
	 * 
	 * The default implementation of LoadVars.onData() invokes LoadVars.onLoad(). You can override this default implementation by
	 * assigning a custom function to LoadVars.onData(), but LoadVars.onLoad() is not called unless you call it in your 
	 * implementation of LoadVars.onData().
	 * 
	 * @param	src	A string or undefined; the raw (unparsed) data from a LoadVars.load() or LoadVars.sendAndLoad() method call.
	 */
	dynamic function onData(src:String):Void;
	
	/**
	 * Invoked when Flash Media Interactive Server receives an HTTP status code from the server. This handler lets you 
	 * capture and act on HTTP status codes.
	 * 
	 * The onHTTPStatus() handler is invoked before onData(), which triggers calls to onLoad() with a value of undefined if the
	 * load fails. After onHTTPStatus() is triggered, onData() is always triggered, whether or not you override onHTTPStatus().
	 * 
	 * @param	httpStatus	A number; the HTTP status code returned by the server. For example, a value of 404 indicates that
	 * 				the server has not found a match for the requested URL. HTTP status codes can be found in sections 10.4 and 
	 * 				10.5 of the HTTP specification. (For more information, see the W3 website at www.w3.org.)
	 * 
	 * @see 	http://help.adobe.com/en_US/FlashMediaServer/3.5_SS_ASD/WS5b3ccc516d4fbf351e63e3d11a11afc95e-7ff7.html
	 */
	dynamic function onHTTPStatus(httpStatus:Int):Void;
	
	/**
	 * Invoked when a LoadVars.load() or LoadVars.sendAndLoad() operation has completed. If the variables load successfully,
	 * the success parameter is true. If the variables were not received, or if an error occurred in receiving the response 
	 * from the server, the success parameter is false. 
	 * @param	success	    A boolean value indicating whether the LoadVars.load() operation ended in success (true)
	 * 				or failure (false).
	 */
	dynamic function onLoad(success:Bool):Void;
}